using Zhaoxi.Zhihu.SharedKerel.Domain;
using Zhaoxi.Zhihu.SharedKerel.Specification;

namespace Zhaoxi.Zhihu.SharedKerel.Repositoy;

public interface IReadRepository<T> where T : class, IEntity<int>
{
    /// <summary>
    /// 查询具有主键实体
    /// </summary>
    /// <param name="id"></param>
    /// <param name="cancellationToken"></param>
    /// <typeparam name="TKey"></typeparam>
    /// <returns></returns>
    Task<T?> GetByIdAsync<TKey>(TKey id, CancellationToken cancellationToken = default);

    /// <summary>
    /// 查询实体集合
    /// </summary>
    /// <param name="specification"></param>
    /// <param name="cancellationToken"></param>
    /// <returns></returns>
    Task<List<T>> GetListAsync(ISpecification<T>? specification=null,CancellationToken cancellationToken = default);
    /// <summary>
    /// 查询实体
    /// </summary>
    /// <param name="specification"></param>
    /// <param name="cancellationToken"></param>
    /// <returns></returns>
    Task<T?> GetSingleOrDefaultAsync(ISpecification<T>? specification=null,CancellationToken cancellationToken = default);
    
    /// <summary>
    /// 统计符合条件总数
    /// </summary>
    /// <param name="specification"></param>
    /// <param name="cancellationToken"></param>
    /// <returns></returns>
    Task<int> CountAsync(ISpecification<T>? specification=null,CancellationToken cancellationToken = default);
    
    /// <summary>
    /// 是否存在符合条件的记录
    /// </summary>
    /// <param name="specification"></param>
    /// <param name="cancellationToken"></param>
    /// <returns></returns>
    Task<bool> AnyAsync(ISpecification<T>? specification=null,CancellationToken cancellationToken = default);
    
}